package com.zxx.pattern.observerPattern.observer1;


/**
 * 被观察者的抽象父类
 *
 * @author zxx on 2021/3/9
 */
public abstract class Subject {

    protected String name;
    protected Object thing;

    abstract void addObserver(Observer observer);

    abstract void removeObserver(Observer observer);

    abstract void notifyObservers();

    public void setThing(Object thing) {
        this.thing = thing;
        System.out.println(this.name + "发布了一条消息: " + thing.toString());
        notifyObservers();
    }
}
